"use strict";
/* Controllers */
app.controller("costTaskTeamListController", ['$scope', '$location', '$rootScope', '$routeParams', 'costTaskTeamListService', function ($scope, $location, $rootScope, $routeParams, costTaskTeamListService) {

    var vm = $scope.vm = {};
    vm.p = {};
    vm.result = {};

    vm.p.buCode = $routeParams.bucode;
    vm.p.period = $routeParams.period;
    vm.p.dt = $routeParams.dt;
    vm.p.type = 'task';

    if(vm.p.dt=='0') {
        vm.p.dt = getNowFormatDate(-1);
    }

    vm.p.period = 'day';
//    vm.d.periodDefines=[
//        'day','week','month','year'
//    ];

    var errorFn = function (result) {
        alert(result);
    };

    $scope.loadCostReportTeam = function () {
        var vm = $scope.vm;
        $scope.listCostReportTeam();
    };

    $scope.listCostReportTeam = function () {
        var vm = $scope.vm;
        vm.result.ms = "...";
        var param = vm.p;
        var procFn = function (response) {
            vm.result.ms = response.ms;
            var data = response.data;
            if (data == null) {
                return;
            }
            vm.result.data = data;
            $('#list_table2').bootstrapTable('load', data);
        };
        costTaskTeamListService.listCostReportTeam(param, procFn, errorFn);
    };
    $scope.initializeController = function () {
        vm.result.ms = '';
        var $resultTable = $('#list_table2');
        $resultTable.bootstrapTable({
             pageList: [30, 50, 100, 300, 500, 1000], pageSize: 30
        });
        $scope.listCostReportTeam();
    };

    $scope.initializeController();

}]);

/* Services */
app.service('costTaskTeamListService', ['ajaxService', function (ajaxService) {

    this.listCostReportTeam = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/cost_report/listCostReport4Team.do", successFunction, errorFunction);
    };
}]);

// 查看指定团队的同学
function costTaskTeamIdFmt(value, row, index) {
    return [
        '<a href="#/star/cost/cost_task_list/0/0/0', '" target="_blank">', " <u>查看明细</u>" , '</a>'
    ].join('');
}

function quotaCuFmt(value, row, index) {
    if(value==null) {
        return '-';
    }
    return value;
}

